function noe2() {
    $("[data-tuiguang]").parentsUntil("#content_left").remove();
    $(".m:contains('广告')").parentsUntil("#content_left").remove();
}

function noe() {


    var countOfClick = 0;
    var index1response = "off";
    var rightAdresponse = "off";
    var imgURL = chrome.extension.getURL("images/Baidu Lite6s.png");
    var imgURLUp = chrome.extension.getURL("images/Baidu Lite6s up.png");


    chrome.storage.sync.get({rightAd: 'on'}, function (items) {
        rightAdresponse = items.rightAd;


        if (items.rightAd == "on") {
            $("#content_right").remove();
            // $("[data-tuiguang]").remove();
            $(".rrecom-btn-close").click(function () {
                alert("点击了");
            });

            console.log("rightAd is " + items.rightAd);

        }

    });


    $("[data-tuiguang]").parentsUntil("#content_left").hide();
    $(".m:contains('广告')").parentsUntil("#content_left").css("display", "none");
    $(".m:contains('广告')").parentsUntil("#content_left").hide();

    chrome.storage.sync.get({index1: 'on'}, function (items) {
        index1response = items.index1;


        if (items.index1 == "on") {
            console.log("index1 is on");

            $(".s_ipt_wr").css({
                "border": "0px",
                "height": "36px",
                "border-radius": "3px 0 0 3px",
                "box-shadow": "-1px 0.7px 5px #aaaaaa"
            });

            $(".s_ipt_wr").hover(function(){
                $(".s_ipt_wr").css({
                    "box-shadow": "-2px 1.5px 8px #bbbbbb"
                });
                $("#su").css({
                    "box-shadow": "0px 1.5px 8px #bbbbbb"
                });
            },function() {
                $(".s_ipt_wr").css({
                    "box-shadow": "-1px 0.7px 5px #aaaaaa"
                });
                $("#su").css({
                    "box-shadow": "0px 0.7px 5px #aaaaaa"
                });
            });
            $(".bg s_btn_wr").mouseover(function () {
                $(".bg s_btn_wr").css({
                    "box-shadow": "1px 1px 5px #888888"
                });
            })
            $("#s_kw_wrap").css({
                "background": "#ffffff"
            });

            if($(".user-name").text()) {
                $("#kw").css({
                    "padding-top": "8px",
                    "padding-bottom": "8px"

                });
            }

            $("#result_logo img").attr("src", imgURLUp);//Baidu Lite6s up

            if (window.location.href == "https://www.baidu.com/") {
                $("body").css("background", "#ffffff");
                $("#lg img").attr("src", imgURL);//baidu Lite6s

            }

            $(".ftCon-Wrapper").hide();
            $("#qrcode").hide();
            $("#u1").hide();

            $(".soutu-btn").hide();
            $(".soutu-btn").css({
                "background": "#ffffff",
                "height": "0px",
                "margin-top":"-2px",
                "top":"65%"
            });

            $(".s_btn").css({"border-bottom":"0px","height":"36px"});
            $(".s_form").css("top", "50%");

            $("#su").css({
                "background": "#f1f1f1",
                "color":"#666666",
                "border-radius": "0 3px 3px 0",
                "box-shadow": "0px 0.7px 5px #aaaaaa"
            });

            $("#su").hover(function(){
                $("#su").css({
                    "box-shadow": "0px 1.5px 8px #bbbbbb"
                });
            },function() {

                $("#su").css({
                    "box-shadow": "0px 0.7px 5px #aaaaaa"
                });
            });

            $(".rrecom-container").hide();
        }

        console.log("index beautify is " + items.index1);
    });

}

noe();

$(document).ready(function () {

    chrome.runtime.onMessage.addListener(
        function(request, sender, sendResponse) {
            console.log(sender.tab ?
                "from a content script:" + sender.tab.url :
                "from the extension");
            if (request.greeting == "hello") {
                sendResponse({farewell: "goodbye"});
                alert("开启“阻止百度追踪”时将无法登录百度产品，如百度贴吧、百度知道等。\n登录百度产品时,关闭该功能并刷新网页即可恢复.");
            }
            if (request.greeting == "reload") {
                sendResponse({farewell: "goodbye"});
                window.location.reload();
            }

        });


    noe();

    $("#su").mousedown(function () {
        noe2();

            var keyword = $("#kw").val();
            var keywordconvert = keyword.replace(/#/g, "%23").replace(/&/g, "%26").replace(/\+/g, "%2B");
            console.log("keywordconvert = " + keywordconvert);
            chrome.runtime.sendMessage({greeting: "cleanCookies"}, function(response) {
            });
            location.href = "https://www.baidu.com/s?ie=utf-8&wd=" + keywordconvert;

    });

    document.onkeydown = function (event) {
        var e = event || window.event || arguments.callee.caller.arguments[0];
        if (e && e.keyCode == 13) { // enter 键
            console.log($("#kw").val());

            var keyword = $("#kw").val();
            // keywordconvert=keyword.replace(/(\w*)#(.*)&(.*)/g, "$1%23$2%26");
            var keywordconvert = keyword.replace(/#/g, "%23").replace(/&/g, "%26").replace(/\+/g, "%2B");
            console.log("keywordconvert = " + keywordconvert);
            chrome.runtime.sendMessage({greeting: "cleanCookies"}, function(response) {
                // console.log(response.farewell);
            });
            location.href = "https://www.baidu.com/s?ie=utf-8&wd=" + keywordconvert;
            noe2();
            noe();

        }
    }

    chrome.storage.sync.get({tuiguangBlock: 'on'}, function (items) {
        if (items.tuiguangBlock == "on") {


            document.getElementById('content_left').addEventListener("DOMNodeInserted", function(){
                noe();
                noe2();
                console.log('列表中子元素被修改');
            }, false);

            document.getElementById('content_right').addEventListener("DOMNodeInserted", function(){
                noe();
                noe2();
                console.log('列表中子元素被修改');
            }, false);


            console.log("tuiguangBlock is " + items.tuiguangBlock);
        }


    });

    chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
        if(message == 'Hello'){
            noe2();
            console.log("MessageReceived");
        }
    });

})